package 
{
	
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.utils.getDefinitionByName;
    
    //--------------------------------------------------------------------------//
    public class Preloader extends MovieClip
    {
		[Embed(source="relojarena.swf",symbol="reloj_arena_mc")]
		
		private static var Loader:Class;
        private var _app:Object;
        private var mcLoader:MovieClip = new Loader(); 
        
        //---------------------------------------------------------------------//
        public function Preloader()
        {
            stop();
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
       	       		
            this.addChild(mcLoader);
        
            mcLoader.x = 600/2-mcLoader.width*0.5;
            mcLoader.y = 400/2-mcLoader.height*0.5;
            mcLoader.scaleX = 1;
            mcLoader.scaleY = 1;
           
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
          
            
            
        }
        //---------------------------------------------------------------------//
      	public function CoreAssetsLoaded(ev:Event):void
      	{
      		 this.removeChild(mcLoader);
      		_app.Initialize();
      	}
      	//---------------------------------------------------------------------//
        public function onEnterFrame(event:Event):void
        {
            graphics.clear();
            if(framesLoaded == totalFrames)
            {
            	trace ("PreLoading complete");
                removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                nextFrame();
                init();
                
            }
            else
            {
     	      	 mcLoader.play();
     	    }
        }
       //---------------------------------------------------------------------//
        private function init():void
        {
            var mainClass:Class = Class(getDefinitionByName("MekanetClient"));
            if(mainClass)
            {
            	
                _app = new mainClass();
                addChild(_app as DisplayObject);
                 _app.Init();
                this.removeChild(mcLoader);
                
                
           	 
            }
        }
        //---------------------------------------------------------------------//
    }
} 
